package com.homework.proxy;

import com.homework.proxy.model.ExecuteCodeRequest;
import com.homework.proxy.model.ExecuteCodeResponse;

import java.util.Arrays;
import java.util.List;

/**
 * @Author : Zan
 * @Create : 2024/6/16 15:06
 * @ClassName : Client
 * @Description : 结构型模式 —— 代理模式的使用
 */
public class Client {
    public static void main(String[] args) {
        // 创建本地代码沙箱实例
        CodeSandBox codeSandBox = new NativeCodeSandBox();
        codeSandBox = new CodeSandBoxProxy(codeSandBox);
        String code = "public class Solution {\n" +
                "    public static void main(String[] args) {\n" +
                "        Integer a = Integer.parseInt(args[0]);\n" +
                "        Integer b = Integer.parseInt(args[1]);\n" +
                "        System.out.println(\"结果: \" + (a + b));\n" +
                "    }\n" +
                "}";
        List<String> inputList = Arrays.asList("1 2", "3 4");
        ExecuteCodeRequest codeRequest = ExecuteCodeRequest.builder()
                .code(code)
                .language("java")
                .inputList(inputList)
                .build();
        ExecuteCodeResponse executeCodeResponse = codeSandBox.executeCode(codeRequest);
        System.out.println("-------------代理结束-------------");
    }
}
